//
//  UIColor+Category.m
//  LNUniversal
//
//  Created by liu nian on 15/5/25.
//  Copyright (c) 2015年 Liu Nian site:http://iliunian.com. All rights reserved.
//

#import "UIColor+Category.h"

@implementation UIColor (Category)
// 根据16进制和alpha计算UIColor
+ (UIColor *)HEX2Color:(NSInteger)hexCode inAlpha:(CGFloat)alpha
{
    float red   = ((hexCode >> 16) & 0x000000FF)/255.0f;
    float green = ((hexCode >> 8) & 0x000000FF)/255.0f;
    float blue  = ((hexCode) & 0x000000FF)/255.0f;
    return [UIColor colorWithRed:red
                           green:green
                            blue:blue
                           alpha:alpha];
}

+(UIColor *)colorWithHex:(NSInteger)hexCode{
    return [self HEX2Color:hexCode inAlpha:1.0f];
}

+(UIColor *)colorWithHex:(NSInteger)hexCode alpha:(CGFloat)alpha{
    return [self HEX2Color:hexCode inAlpha:alpha];
}

+(UIColor *)colorWithRandom{
    return [UIColor colorWithRed:(arc4random() % 255)/255.0
                           green:(arc4random() % 255)/255.0
                            blue:(arc4random() % 255)/255.0
                           alpha:(arc4random() % 255)/255.0];
}

@end
